package com.dongdongshop.controller;

import com.alibaba.fastjson.JSONObject;
import com.dongdongshop.admin.vo.TypeTemplateVO;
import com.dongdongshop.common.Result;
import com.dongdongshop.em.PageRequest;
import com.dongdongshop.em.PageResult;
import com.dongdongshop.service.TypeTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("TypeTemplateController")
public class TypeTemplateController {
    @Autowired
    private TypeTemplateService typeTemplateService;

    @PostMapping("typrselect")
    public Result select(@RequestBody PageRequest<TypeTemplateVO> typeVo){
        PageResult pageResult = typeTemplateService.TypeSelect(typeVo);
        return Result.OK().setData(pageResult);
    }

    @PostMapping("addType")
    public Result addType(@RequestBody TypeTemplateVO typeTemplateVO) {
        typeTemplateService.add(typeTemplateVO);
        return Result.OK();
    }

    @PostMapping("selectById")
    public Result selectById(@RequestParam Long id){
       TypeTemplateVO vo = typeTemplateService.getById(id);
       return Result.OK().setData(vo);
    }

    @PostMapping("updateType")
    public Result updateType(@RequestBody TypeTemplateVO typeTemplateVO){
        typeTemplateService.update(typeTemplateVO);
        return Result.OK();
    }

    @DeleteMapping("delete")
    public Result delete(@RequestParam Long ids[]) {
        typeTemplateService.delete(ids);
        return Result.OK();
    }
}
